import Map from "@arcgis/core/Map.js";
import Basemap from "@arcgis/core/Basemap.js";
import MapView from "@arcgis/core/views/MapView.js";
import SceneView from "@arcgis/core/views/SceneView.js";
import ElevationLayer from "@arcgis/core/layers/ElevationLayer.js";
import WebTileLayer from "@arcgis/core/layers/WebTileLayer.js";
import TileLayer from "@arcgis/core/layers/TileLayer.js";
import MapImageLayer from "@arcgis/core/layers/MapImageLayer.js";
import FeatureLayer from "@arcgis/core/layers/FeatureLayer.js";
import TileInfo from "@arcgis/core/layers/support/TileInfo.js";
import Point from "@arcgis/core/geometry/Point.js";
import ScaleBar from "@arcgis/core/widgets/ScaleBar.js";
import TimeSlider from "@arcgis/core/widgets/TimeSlider.js";
import {
	$config
} from './config/gis_config'

export class LoadMap {

	// _map: null,
	// _view: null,
	// _toolbar: null,
	// _showToolbar: false, //工具条
	// _showScaleBar: false, //比例尺
	// _showOverviewMap: false, //鹰眼
	// _showVerticalZoombar: false, //垂直缩放条
	// _viewDivId: null,
	// _slider: null,
	// _timeSlider: null, //时间滑块部件

	constructor(viewDivId, showToolbar, timeSliderId) {
		var me = this;
		//添加代理
		// var proxyurl = $config.gisConfig.proxyurl;
		// if (lang.isString(proxyurl) && proxyurl != "" && proxyurl != "undefined") {
		// 	esriConfig.request.proxyUrl = proxyurl; //all requests in your application use the same proxy
		// }
		// configure application with specific proxy rules
		// urlUtils.addProxyRule({
		// 	urlPrefix: "route.arcgis.com",
		// 	proxyUrl: "/resource-proxy/Java/proxy.php"
		// });


		me._viewDivId = viewDivId;
		me._map = new Map({});
		//添加默认天地图底图服务
		this.addTDTBaseLayer(me._map);
		console.log(4);

		var layer_gl = null; //管龄时态数据

		//底图之上，添加ArcGIS发布的服务底图
		var mapServers = $config.gisConfig.mapServers;
		//添加地图服务
		mapServers.forEach(function(item){
			if (item.url) {
				var layer = me.createLayer(item);
				if (layer) {
					me._map.add(layer);
				}
				if (item.id == "GL") {
					layer_gl = layer;
				}
			}
		})
		// arrayUtil.forEach(mapServers, function(item) {
		// 	if (item.url) {
		// 		var layer = this.createLayer(item);
		// 		if (layer) {
		// 			this._map.add(layer);
		// 		}
		// 		if (item.id == "GL") {
		// 			layer_gl = layer;
		// 		}
		// 	}
		// }, this);
		me._view = new MapView({
			container: me._viewDivId,
			map: me._map,
			center: $config.gisConfig.centerPoint,
			scale: $config.gisConfig.scale
		});
		//时间滑块
		if (timeSliderId != null && timeSliderId != undefined) {
			me._timeSlider = new TimeSlider({
				container: timeSliderId,
				mode: "instant",
				view: me._view,
				timeVisible: true,
				loop: false,
			});
		}
		// view监听，地图加载完后回调
		me._view.when(function() {
			me._view.popup.autoOpenEnabled = false; //禁用自带的点击弹窗属性
			// All the resources in the MapView and the map have loaded. Now execute additional processes
			me.mapLoadHandler();
			// 去除地图双击放大事件
			me._view.on('double-click', function(evt) {
				evt.stopPropagation();
			});

			//定制管龄专题图
			if (layer_gl != null) {
				const fullTimeExtent = layer_gl.timeInfo.fullTimeExtent;
				// set up time slider properties
				me._timeSlider.fullTimeExtent = fullTimeExtent;
				me._timeSlider.stops = {
					interval: layer_gl.timeInfo.interval
				};
			}


			// 控制图层的缩放级别
			// me._view.on('mouse-wheel', function (evt) {
			// 	//鼠标滚轮缩小
			// 	if (evt.deltaY > 0 && me._view.scale > 9000000) {
			// 		evt.stopPropagation();
			// 		return false;
			// 	}
			// 	//鼠标滚轮放大
			// 	else if (evt.deltaY < 0 && me._view.scale < 10) {
			// 		evt.stopPropagation();
			// 		return false;
			// 	}
			// 	if ((evt.deltaY > 0 && me._view.scale > 9000000) || (evt.deltaY < 0 && me._view.scale < 10)) {
			// 		console.info(me._view);
			// 		console.info(evt);
			// 	}
			// });

		}, function(error) {
			// Use the errback function to handle when the view doesn't load properly
			console.log("The view's resources failed to load: ", error);
		});
	}
	//view初始化完成后执行的方法
	mapLoadHandler() {
		var me = this;
		me._view.ui.remove("zoom"); //移除原有缩放工具
		me._view.ui.remove("attribution"); //移除底部ESRI logo
		var _center = $config.gisConfig.centerPoint;
		var _scale = $config.gisConfig.scale;
		// var _initialExtent = $config.gisConfig.initialExtent;

		if (typeof(_scale) != "undefined") {
			me._view.scale = _scale;
		}

		if (typeof(_center) != "undefined") {
			var centerPoint = new Point({
				x: _center[0],
				y: _center[1],
				spatialReference: me._view.spatialReference
			});
			me._view.center = centerPoint;
		}

		// if (typeof (_initialExtent) != "undefined") {
		// 	me._view.goTo(new Extent({
		// 		xmin: _initialExtent[0],
		// 		ymin: _initialExtent[1],
		// 		xmax: _initialExtent[2],
		// 		ymax: _initialExtent[3],
		// 		spatialReference: me._view.spatialReference
		// 	}));
		// }
		//是否显示比例尺
		me._showScaleBar = $config.gisConfig.showScaleBar;
		if (me._showScaleBar) {
			var scaleBar = new ScaleBar({
				view: me._view,
				style: 'line',
				unit: 'metric' //单位km，默认mile
			});
			// Add widget to the bottom left corner of the view
			me._view.ui.add(scaleBar, {
				position: "bottom-left"
			});
			// new Scalebar({ map: this._map });
		}
		//是否显示工具条
		//是否显示toolbar工具栏 
		// me._showToolbar = $config.gisConfig.showToolbar;;
		// if (me._showToolbar) {
		// 	var mapDiv = dom.byId(me._viewDivId);
		// 	var mapToolDiv = document.createElement('div');
		// 	mapToolDiv.id = 'mapToolbar_' + me._viewDivId;
		// 	var params = {
		// 		map: me._map,
		// 		viewDivId: me._viewDivId
		// 	};
		// 	me._toolbar = new Toolbar(params);
		// 	me._toolbar.placeAt(mapToolDiv);
		// 	mapDiv.appendChild(mapToolDiv);
		// }
		//是否显示鹰眼
		// me._showOverviewMap =  $config.gisConfig.showOverviewMap;
		// if (me._showOverviewMap) {
		// 	new OverviewMap({ map: this._map });
		// }

		//是否显示垂直缩放条
		// me._showVerticalZoombar =  $config.gisConfig.showVerticalZoombar;
		// if (me._showVerticalZoombar) {
		// 	new VerticalZoombar({ map: this._map });
		// }

	}

	//返回Map对象
	getMap() {
		return this._map;
	}
	//返回View对象
	getView() {
		return this._view;
	}
	//返回toolbar对象
	getToolbar() {
		return this._toolbar;
	}
	//返回timeSlider对象
	getTimeSlider() {
		return this._timeSlider;
	}
	//添加设置天地图底图为map地图控件的basemap
	addTDTBaseLayer(map) {
		let that = this;
		var TDTmapServers = $config.gisConfig.mapBaseTDTLayerServers;
		if (TDTmapServers != undefined) {
			var tdt_basemap = new Basemap({
				title: "基础底图",
				id: "tdt_basemap"
			});
			TDTmapServers.forEach(function(item) {
				if (item.url) {
					var layer = that.createLayer(item);
					if (layer) {
						tdt_basemap.baseLayers.add(layer);
					}
				}
			})
			// arrayUtil.forEach(TDTmapServers, function(item) {
			// 	if (item.url) {

			// 		var layer = this.createLayer(item);
			// 		if (layer) {
			// 			tdt_basemap.baseLayers.add(layer);
			// 		}
			// 	}
			// }, this);
			map.basemap = tdt_basemap;
			// if(this._view != null){
			// 	//var center = mapView.center;
			// 	//var scale = mapView.scale; 
			// 	//先销毁再创建，不然后台报错
			// 	this._view.destroy();
			// 	this._view = new MapView({
			// 		map: map,
			// 		container: this._viewDivId,
			// 		center: $config.gisConfig.centerPoint,
			// 		scale:  $config.gisConfig.scale
			// 	});
			// 	//this._view.extent = extent;
			// }
		}


	}
	//添加设置影像底图为map地图控件的basemap
	addYXMapBaseLayer(map) {
		var YXmapServers = $config.gisConfig.mapBaseTDTYXLayerServers;
		if (YXmapServers != undefined) {
			var tdt_basemap = new Basemap({
				title: "基础底图",
				id: "tdt_basemap"
			});
			arrayUtil.forEach(YXmapServers, function(item) {
				if (item.url) {

					var layer = this.createLayer(item);
					if (layer) {
						tdt_basemap.baseLayers.add(layer);
					}
				}
			}, this);
			map.basemap = tdt_basemap;
		}
	}
	// 添加设置云底图为map地图控件的basemap
	addYunTuMapBaseLayer(map) {
		var YXmapServers = $config.gisConfig.mapBaseYunTuLayerServers;
		if (YXmapServers != undefined) {
			var tdt_basemap = new Basemap({
				title: "基础底图",
				id: "tdt_basemap"
			});
			arrayUtil.forEach(YXmapServers, function(item) {
				if (item.url) {

					var layer = this.createLayer(item);
					if (layer) {
						tdt_basemap.baseLayers.add(layer);
					}
				}
			}, this);
			map.basemap = tdt_basemap;
		}
	}
	//添加设置矢量切片底图为map地图控件的basemap
	addTiledVectorMapBaseLayer(map) {
		var YXmapServers = $config.gisConfig.mapBaseTiledVectorLayerServers;
		if (YXmapServers != undefined) {
			var tdt_basemap = new Basemap({
				title: "基础底图",
				id: "tdt_basemap"
			});
			arrayUtil.forEach(YXmapServers, function(item) {
				if (item.url) {

					var layer = this.createLayer(item);
					if (layer) {
						tdt_basemap.baseLayers.add(layer);
					}
				}
			}, this);
			map.basemap = tdt_basemap;
		}
	}
	//添加设置三维地图为map地图控件的basemap
	add3DMapDemBaseLayer(map) {
		var threeDMapServers = $config.gisConfig.threeDimenBaseMap;
		//假如有配置三维图层信息，先改变配置转换，假如没有，直接转换即可
		if (threeDMapServers != undefined) {
			var tdt_basemap = new Basemap({
				title: "基础底图",
				id: "gaode_basemap"
			});
			arrayUtil.forEach(threeDMapServers, function(item) {
				if (item.type == "elevation") {
					if (item.url) {
						//创建高程图层
						var elevationLayer = new ElevationLayer({
							url: item.url
						});
						if (elevationLayer) {
							map.ground.layers.add(elevationLayer); //添加高程
						}
					}
				} else {
					if (item.url) {
						var layer = this.createLayer(item);
						if (layer) {
							tdt_basemap.baseLayers.add(layer);
						}
					}
				}

			}, this);
			map.basemap = tdt_basemap;

		}
		//创建三维地图，记录当前二维地图范围，保持二三维同步
		if (this._view != null) {
			//var extent = this._view.extent;
			//var center = mapView.center;
			//var scale = mapView.scale; 
			//先销毁再创建，不然后台报错
			this._view.destroy();
			this._view = new SceneView({
				map: map,
				container: this._viewDivId
			});
			//this._view.extent = extent;
		}
	}
	//创建图层
	createLayer(layerCreationProperties) {
		var layerType = layerCreationProperties.type.toLowerCase();
		var layer;
		switch (layerType) {
			case "tdt_webtilelayer": //加载在线地图（现在主要实现天地图的加载）
				layer = this.createTDTWebTiledLayer(layerCreationProperties);
				break;
			case "tiled":
				layer = this.createTiledLayer(layerCreationProperties);
				break;
			case "dynamic":
				layer = this.createDynamicLayer(layerCreationProperties);
				break;
			case "feature":
				layer = this.createFeatureLayer(layerCreationProperties);
				break;
			case "image":
				layer = this.createImageLayer(layerCreationProperties);
				break;
			case "baidu":
				layer = this.createBaiDuLayer(layerCreationProperties);
				break;
			case "tianditu_img":
				layer = this.createTianDiTiledYXMapServiceLayer_qg(layerCreationProperties);
				break;
			case "tianditu_img_label":
				layer = this.createTianDiTiledYXlableMapServiceLayer_qg(layerCreationProperties);
				break;
			case "tianditu":
				layer = this.createTianDiTiledMapServiceLayer_qg(layerCreationProperties);
				break;
			case "tianditu_label":
				layer = this.createTianDiTiledlableMapServiceLayer_qg(layerCreationProperties);
				break;
			default:
				layer = null;
		}
		return layer;
	}
	//createWebTiledLayer,创建天地图底图
	createTDTWebTiledLayer(layerCreationProperties) {
		let that = this
		// 首先设定瓦片信息，天地图经纬度地图的切片信息全部使用该信息设定
		const tileInfo = new TileInfo({
			dpi: 96,
			rows: 256,
			cols: 256,
			compressionQuality: 0,
			origin: {
				x: -180,
				y: 90
			},
			spatialReference: {
				wkid: that._view.spatialReference.wkid
			},
			lods: [{
					level: 0,
					levelValue: 1,
					resolution: 0.703125,
					scale: 295497593.05875003
				},
				{
					level: 1,
					levelValue: 2,
					resolution: 0.3515625,
					scale: 147748796.52937502
				},
				{
					level: 2,
					levelValue: 3,
					resolution: 0.17578125,
					scale: 73874398.264687508
				},
				{
					level: 3,
					levelValue: 4,
					resolution: 0.087890625,
					scale: 36937199.132343754
				},
				{
					level: 4,
					levelValue: 5,
					resolution: 0.0439453125,
					scale: 18468599.566171877
				},
				{
					level: 5,
					levelValue: 6,
					resolution: 0.02197265625,
					scale: 9234299.7830859385
				},
				{
					level: 6,
					levelValue: 7,
					resolution: 0.010986328125,
					scale: 4617149.8915429693
				},
				{
					level: 7,
					levelValue: 8,
					resolution: 0.0054931640625,
					scale: 2308574.9457714846
				},
				{
					level: 8,
					levelValue: 9,
					resolution: 0.00274658203125,
					scale: 1154287.4728857423
				},
				{
					level: 9,
					levelValue: 10,
					resolution: 0.001373291015625,
					scale: 577143.73644287116
				},
				{
					level: 10,
					levelValue: 11,
					resolution: 0.0006866455078125,
					scale: 288571.86822143558
				},
				{
					level: 11,
					levelValue: 12,
					resolution: 0.00034332275390625,
					scale: 144285.93411071779
				},
				{
					level: 12,
					levelValue: 13,
					resolution: 0.000171661376953125,
					scale: 72142.967055358895
				},
				{
					level: 13,
					levelValue: 14,
					resolution: 8.58306884765625e-005,
					scale: 36071.483527679447
				},
				{
					level: 14,
					levelValue: 15,
					resolution: 4.291534423828125e-005,
					scale: 18035.741763839724
				},
				{
					level: 15,
					levelValue: 16,
					resolution: 2.1457672119140625e-005,
					scale: 9017.8708819198619
				},
				{
					level: 16,
					levelValue: 17,
					resolution: 1.0728836059570313e-005,
					scale: 4508.9354409599309
				},
				{
					level: 17,
					levelValue: 18,
					resolution: 5.3644180297851563e-006,
					scale: 2254.4677204799655
				},
				{
					level: 18,
					levelValue: 19,
					resolution: 2.68220901489257815e-006,
					scale: 1127.23386023998275
				},
				{
					level: 19,
					levelValue: 20,
					resolution: 1.341104507446289075e-006,
					scale: 563.616930119991375
				}
			]
		})
		let TDTtiledLayer = new WebTileLayer({
			urlTemplate: layerCreationProperties.url + layerCreationProperties.key,
			subDomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],
			tileInfo,
			copyright: layerCreationProperties.label || "天地图",
			spatialReference: that._view.spatialReference,
			token: layerCreationProperties.key
		});
		TDTtiledLayer.opacity = !isNaN(layerCreationProperties.opacity) ? layerCreationProperties.opacity : 1;
		TDTtiledLayer.id = layerCreationProperties.id;
		TDTtiledLayer.title = layerCreationProperties.label;
		if (layerCreationProperties.visible === undefined) {
			TDTtiledLayer.visible = true; //节点不存在
		} else {
			TDTtiledLayer.visible = layerCreationProperties.visible;
		}
		return TDTtiledLayer;
	}


	// 切片图层(3.x: ArcGISTiledLayer;4.x: TileLayer)
	createTiledLayer(layerCreationProperties) {
		var tiledLayer = new TileLayer(layerCreationProperties.url);
		tiledLayer.opacity = !isNaN(layerCreationProperties.opacity) ? layerCreationProperties.opacity : 1;
		tiledLayer.id = layerCreationProperties.id;
		tiledLayer.title = layerCreationProperties.label;
		if (layerCreationProperties.visible == undefined) //节点不存在
			tiledLayer.visible = true;
		else
			tiledLayer.visible = layerCreationProperties.visible;
		if (!isNaN(layerCreationProperties.minScale)) {
			tiledLayer.minScale = layerCreationProperties.minScale;
		}
		if (!isNaN(layerCreationProperties.maxScale)) {
			tiledLayer.maxScale = layerCreationProperties.maxScale;
		}
		return tiledLayer;
	}

	//创建动态图层(3.x:DynamicLayer;4.x:MapImageLayer)
	createDynamicLayer(layerCreationProperties) {
		if (layerCreationProperties.sublayers) {
			let sublayers = [];
			layerCreationProperties.sublayers.forEach(item => {
				sublayers.push({
					id: item,
					visible: true
				});
			});
			layerCreationProperties._sublayers.forEach(item => {
				sublayers.push({
					id: item,
					visible: false
				});
			});
			var dynLayer = new MapImageLayer({
				url: layerCreationProperties.url,
				sublayers: sublayers
			});
		} else {
			var dynLayer = new MapImageLayer(layerCreationProperties.url);
		}
		dynLayer.opacity = !isNaN(layerCreationProperties.opacity) ? layerCreationProperties.opacity : 1;
		dynLayer.id = layerCreationProperties.id;
		dynLayer.title = layerCreationProperties.label;
		if (layerCreationProperties.visible == undefined) //节点不存在
			dynLayer.visible = true;
		else
			dynLayer.visible = layerCreationProperties.visible;
		if (!isNaN(layerCreationProperties.minScale)) {
			dynLayer.minScale = layerCreationProperties.minScale;
		}
		if (!isNaN(layerCreationProperties.maxScale)) {
			dynLayer.maxScale = layerCreationProperties.maxScale;
		}
		return dynLayer;
	}
	createFeatureLayer(layerCreationProperties) {
		var featureLayer = new FeatureLayer(layerCreationProperties.url);
		featureLayer.opacity = !isNaN(layerCreationProperties.opacity) ? layerCreationProperties.opacity : 1;
		featureLayer.id = layerCreationProperties.id;
		featureLayer.title = layerCreationProperties.label;
		if (layerCreationProperties.visible == undefined) //节点不存在
			featureLayer.visible = true;
		else
			featureLayer.visible = layerCreationProperties.visible;
		if (!isNaN(layerCreationProperties.minScale)) {
			featureLayer.minScale = layerCreationProperties.minScale;
		}
		if (!isNaN(layerCreationProperties.maxScale)) {
			featureLayer.maxScale = layerCreationProperties.maxScale;
		}
		return featureLayer;
	}
	//创建全国天地图影像地图服务
	createTianDiTiledYXMapServiceLayer_qg(layerCreationProperties) {
		var tileInfo = new TileInfo({
			dpi: 96,
			rows: 256,
			cols: 256,
			compressionQuality: 0,
			origin: {
				x: -180,
				y: 90
			},
			spatialReference: {
				wkid: 4490
			},
			lods: [{
					level: 0,
					levelValue: 1,
					resolution: 0.703125,
					scale: 295497593.05875003
				},
				{
					level: 1,
					levelValue: 2,
					resolution: 0.3515625,
					scale: 147748796.52937502
				},
				{
					level: 2,
					levelValue: 3,
					resolution: 0.17578125,
					scale: 73874398.264687508
				},
				{
					level: 3,
					levelValue: 4,
					resolution: 0.087890625,
					scale: 36937199.132343754
				},
				{
					level: 4,
					levelValue: 5,
					resolution: 0.0439453125,
					scale: 18468599.566171877
				},
				{
					level: 5,
					levelValue: 6,
					resolution: 0.02197265625,
					scale: 9234299.7830859385
				},
				{
					level: 6,
					levelValue: 7,
					resolution: 0.010986328125,
					scale: 4617149.8915429693
				},
				{
					level: 7,
					levelValue: 8,
					resolution: 0.0054931640625,
					scale: 2308574.9457714846
				},
				{
					level: 8,
					levelValue: 9,
					resolution: 0.00274658203125,
					scale: 1154287.4728857423
				},
				{
					level: 9,
					levelValue: 10,
					resolution: 0.001373291015625,
					scale: 577143.73644287116
				},
				{
					level: 10,
					levelValue: 11,
					resolution: 0.0006866455078125,
					scale: 288571.86822143558
				},
				{
					level: 11,
					levelValue: 12,
					resolution: 0.00034332275390625,
					scale: 144285.93411071779
				},
				{
					level: 12,
					levelValue: 13,
					resolution: 0.000171661376953125,
					scale: 72142.967055358895
				},
				{
					level: 13,
					levelValue: 14,
					resolution: 8.58306884765625e-005,
					scale: 36071.483527679447
				},
				{
					level: 14,
					levelValue: 15,
					resolution: 4.291534423828125e-005,
					scale: 18035.741763839724
				},
				{
					level: 15,
					levelValue: 16,
					resolution: 2.1457672119140625e-005,
					scale: 9017.8708819198619
				},
				{
					level: 16,
					levelValue: 17,
					resolution: 1.0728836059570313e-005,
					scale: 4508.9354409599309
				},
				{
					level: 17,
					levelValue: 18,
					resolution: 5.3644180297851563e-006,
					scale: 2254.4677204799655
				},
				{
					level: 18,
					levelValue: 19,
					resolution: 2.68220901489257815e-006,
					scale: 1127.23386023998275
				},
				{
					level: 19,
					levelValue: 20,
					resolution: 1.341104507446289075e-006,
					scale: 563.616930119991375
				}
			]
		});
		var layer = new WebTileLayer({ // 天地图影像地图
			urlTemplate: "http://{subDomain}.tianditu.gov.cn/img_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=08a7cd65c70eff4150ef03e388ded03e",
			subDomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],
			tileInfo: tileInfo,
			copyright: '天地图',
			spatialReference: {
				wkid: 4490
			},
			id: layerCreationProperties.id
		});
		return layer;
	}
	//创建全国天地图影像注记地图服务
	createTianDiTiledYXlableMapServiceLayer_qg(layerCreationProperties) {
		var tileInfo = new TileInfo({
			dpi: 96,
			rows: 256,
			cols: 256,
			compressionQuality: 0,
			origin: {
				x: -180,
				y: 90
			},
			spatialReference: {
				wkid: 4490
			},
			lods: [{
					level: 0,
					levelValue: 1,
					resolution: 0.703125,
					scale: 295497593.05875003
				},
				{
					level: 1,
					levelValue: 2,
					resolution: 0.3515625,
					scale: 147748796.52937502
				},
				{
					level: 2,
					levelValue: 3,
					resolution: 0.17578125,
					scale: 73874398.264687508
				},
				{
					level: 3,
					levelValue: 4,
					resolution: 0.087890625,
					scale: 36937199.132343754
				},
				{
					level: 4,
					levelValue: 5,
					resolution: 0.0439453125,
					scale: 18468599.566171877
				},
				{
					level: 5,
					levelValue: 6,
					resolution: 0.02197265625,
					scale: 9234299.7830859385
				},
				{
					level: 6,
					levelValue: 7,
					resolution: 0.010986328125,
					scale: 4617149.8915429693
				},
				{
					level: 7,
					levelValue: 8,
					resolution: 0.0054931640625,
					scale: 2308574.9457714846
				},
				{
					level: 8,
					levelValue: 9,
					resolution: 0.00274658203125,
					scale: 1154287.4728857423
				},
				{
					level: 9,
					levelValue: 10,
					resolution: 0.001373291015625,
					scale: 577143.73644287116
				},
				{
					level: 10,
					levelValue: 11,
					resolution: 0.0006866455078125,
					scale: 288571.86822143558
				},
				{
					level: 11,
					levelValue: 12,
					resolution: 0.00034332275390625,
					scale: 144285.93411071779
				},
				{
					level: 12,
					levelValue: 13,
					resolution: 0.000171661376953125,
					scale: 72142.967055358895
				},
				{
					level: 13,
					levelValue: 14,
					resolution: 8.58306884765625e-005,
					scale: 36071.483527679447
				},
				{
					level: 14,
					levelValue: 15,
					resolution: 4.291534423828125e-005,
					scale: 18035.741763839724
				},
				{
					level: 15,
					levelValue: 16,
					resolution: 2.1457672119140625e-005,
					scale: 9017.8708819198619
				},
				{
					level: 16,
					levelValue: 17,
					resolution: 1.0728836059570313e-005,
					scale: 4508.9354409599309
				},
				{
					level: 17,
					levelValue: 18,
					resolution: 5.3644180297851563e-006,
					scale: 2254.4677204799655
				},
				{
					level: 18,
					levelValue: 19,
					resolution: 2.68220901489257815e-006,
					scale: 1127.23386023998275
				},
				{
					level: 19,
					levelValue: 20,
					resolution: 1.341104507446289075e-006,
					scale: 563.616930119991375
				}
			]
		});
		var layer = new WebTileLayer({
			urlTemplate: "http://{subDomain}.tianditu.gov.cn/cia_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=08a7cd65c70eff4150ef03e388ded03e",
			subDomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],
			tileInfo: tileInfo,
			copyright: '天地图',
			spatialReference: {
				wkid: 4490
			},
			id: layerCreationProperties.id
		});
		return layer;
	}
	//创建全国天地图矢量地图服务
	createTianDiTiledMapServiceLayer_qg(layerCreationProperties) {
		var tileInfo = new TileInfo({
			dpi: 96,
			rows: 256,
			cols: 256,
			compressionQuality: 0,
			origin: {
				x: -180,
				y: 90
			},
			spatialReference: {
				wkid: 4490
			},
			lods: [{
					level: 0,
					levelValue: 1,
					resolution: 0.703125,
					scale: 295497593.05875003
				},
				{
					level: 1,
					levelValue: 2,
					resolution: 0.3515625,
					scale: 147748796.52937502
				},
				{
					level: 2,
					levelValue: 3,
					resolution: 0.17578125,
					scale: 73874398.264687508
				},
				{
					level: 3,
					levelValue: 4,
					resolution: 0.087890625,
					scale: 36937199.132343754
				},
				{
					level: 4,
					levelValue: 5,
					resolution: 0.0439453125,
					scale: 18468599.566171877
				},
				{
					level: 5,
					levelValue: 6,
					resolution: 0.02197265625,
					scale: 9234299.7830859385
				},
				{
					level: 6,
					levelValue: 7,
					resolution: 0.010986328125,
					scale: 4617149.8915429693
				},
				{
					level: 7,
					levelValue: 8,
					resolution: 0.0054931640625,
					scale: 2308574.9457714846
				},
				{
					level: 8,
					levelValue: 9,
					resolution: 0.00274658203125,
					scale: 1154287.4728857423
				},
				{
					level: 9,
					levelValue: 10,
					resolution: 0.001373291015625,
					scale: 577143.73644287116
				},
				{
					level: 10,
					levelValue: 11,
					resolution: 0.0006866455078125,
					scale: 288571.86822143558
				},
				{
					level: 11,
					levelValue: 12,
					resolution: 0.00034332275390625,
					scale: 144285.93411071779
				},
				{
					level: 12,
					levelValue: 13,
					resolution: 0.000171661376953125,
					scale: 72142.967055358895
				},
				{
					level: 13,
					levelValue: 14,
					resolution: 8.58306884765625e-005,
					scale: 36071.483527679447
				},
				{
					level: 14,
					levelValue: 15,
					resolution: 4.291534423828125e-005,
					scale: 18035.741763839724
				},
				{
					level: 15,
					levelValue: 16,
					resolution: 2.1457672119140625e-005,
					scale: 9017.8708819198619
				},
				{
					level: 16,
					levelValue: 17,
					resolution: 1.0728836059570313e-005,
					scale: 4508.9354409599309
				},
				{
					level: 17,
					levelValue: 18,
					resolution: 5.3644180297851563e-006,
					scale: 2254.4677204799655
				},
				{
					level: 18,
					levelValue: 19,
					resolution: 2.68220901489257815e-006,
					scale: 1127.23386023998275
				},
				{
					level: 19,
					levelValue: 20,
					resolution: 1.341104507446289075e-006,
					scale: 563.616930119991375
				}
			]
		});
		var layer = new WebTileLayer({ // 天地图影像地图
			urlTemplate: "http://{subDomain}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=942d12933c0e66b61023fd2a026deba6",
			subDomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],
			tileInfo: tileInfo,
			copyright: '天地图',
			spatialReference: {
				wkid: 4490
			},
			id: layerCreationProperties.id
		});
		return layer;
	}
	//创建全国天地图矢量注记地图服务
	createTianDiTiledlableMapServiceLayer_qg(layerCreationProperties) {
		var tileInfo = new TileInfo({
			dpi: 96,
			rows: 256,
			cols: 256,
			compressionQuality: 0,
			origin: {
				x: -180,
				y: 90
			},
			spatialReference: {
				wkid: 4490
			},
			lods: [{
					level: 0,
					levelValue: 1,
					resolution: 0.703125,
					scale: 295497593.05875003
				},
				{
					level: 1,
					levelValue: 2,
					resolution: 0.3515625,
					scale: 147748796.52937502
				},
				{
					level: 2,
					levelValue: 3,
					resolution: 0.17578125,
					scale: 73874398.264687508
				},
				{
					level: 3,
					levelValue: 4,
					resolution: 0.087890625,
					scale: 36937199.132343754
				},
				{
					level: 4,
					levelValue: 5,
					resolution: 0.0439453125,
					scale: 18468599.566171877
				},
				{
					level: 5,
					levelValue: 6,
					resolution: 0.02197265625,
					scale: 9234299.7830859385
				},
				{
					level: 6,
					levelValue: 7,
					resolution: 0.010986328125,
					scale: 4617149.8915429693
				},
				{
					level: 7,
					levelValue: 8,
					resolution: 0.0054931640625,
					scale: 2308574.9457714846
				},
				{
					level: 8,
					levelValue: 9,
					resolution: 0.00274658203125,
					scale: 1154287.4728857423
				},
				{
					level: 9,
					levelValue: 10,
					resolution: 0.001373291015625,
					scale: 577143.73644287116
				},
				{
					level: 10,
					levelValue: 11,
					resolution: 0.0006866455078125,
					scale: 288571.86822143558
				},
				{
					level: 11,
					levelValue: 12,
					resolution: 0.00034332275390625,
					scale: 144285.93411071779
				},
				{
					level: 12,
					levelValue: 13,
					resolution: 0.000171661376953125,
					scale: 72142.967055358895
				},
				{
					level: 13,
					levelValue: 14,
					resolution: 8.58306884765625e-005,
					scale: 36071.483527679447
				},
				{
					level: 14,
					levelValue: 15,
					resolution: 4.291534423828125e-005,
					scale: 18035.741763839724
				},
				{
					level: 15,
					levelValue: 16,
					resolution: 2.1457672119140625e-005,
					scale: 9017.8708819198619
				},
				{
					level: 16,
					levelValue: 17,
					resolution: 1.0728836059570313e-005,
					scale: 4508.9354409599309
				},
				{
					level: 17,
					levelValue: 18,
					resolution: 5.3644180297851563e-006,
					scale: 2254.4677204799655
				},
				{
					level: 18,
					levelValue: 19,
					resolution: 2.68220901489257815e-006,
					scale: 1127.23386023998275
				},
				{
					level: 19,
					levelValue: 20,
					resolution: 1.341104507446289075e-006,
					scale: 563.616930119991375
				}
			]
		});
		var layer = new WebTileLayer({ // 天地图影像地图
			urlTemplate: "http://{subDomain}.tianditu.gov.cn/cva_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=942d12933c0e66b61023fd2a026deba6",
			subDomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],
			tileInfo: tileInfo,
			copyright: '天地图',
			spatialReference: {
				wkid: 4490
			},
			id: layerCreationProperties.id
		});
		return layer;
	}
	/*//创建天地图切片地图服务
	createTianDiTiledMapServiceLayer : function(layerCreationProperties){
		var tianDiLayer = new TianDiTiledMapServiceLayer(layerCreationProperties.url);
		tianDiLayer.id = layerCreationProperties.id;
		return tianDiLayer;
	},*/
	/*//创建百度切片地图服务
	createBaiDuLayer: function (layerCreationProperties) {
		var baiDuLayer = new BaiDuLayer();
		baiDuLayer.id = layerCreationProperties.id;
		return baiDuLayer;
	}*/
}